<?php
/**
 * FAQ.php
 *
 * @author camfee <camfee@foxmail.com>
 * @date   17-9-18 下午4:38
 *
 */

define("SITE_AUTH", 'recom-faq');

require '../../../common.inc.php';

use Mobile\RecomData;

class FAQ extends \lib\core\Action
{
    public function doDefault()
    {
        if (!empty($_POST['title']) && !empty($_POST['text'])) {
            $data = [];
            foreach ($_POST['title'] as $k => $v) {
                if (!empty($v) && !empty($_POST['text'][$k])) {
                    $data[$k]['Title'] = $v;
                    $data[$k]['Text'] = str_replace(PHP_EOL, '<br>', $_POST['text'][$k]);
                }
            }
            RecomData::setData(RecomData::APP_FAQ_TEXT, $data);
        }
        $list = RecomData::getData(RecomData::APP_FAQ_TEXT)[RecomData::APP_FAQ_TEXT];
        if (!empty($list)) {
            foreach ($list as $k => $v) {
                $list[$k]['Text'] = str_replace('<br>', PHP_EOL, $v['Text']);
            }
        }

        $smarty = $this->app->page();
        $smarty->value('list', $list);

        $smarty->output('recom/FAQ.tpl');
    }
}

$app->run();